package edu.cth.scrabbit.shared;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * A class to represent the actual game board.
 * 
 * @author Anders Jonsson, Marcus Harryson
 * 
 */
public class GameState implements Serializable {
	private static final long serialVersionUID = 1135805114517804631L;

	private List<GameLetter> letters = new ArrayList<GameLetter>();
	private Player[] players;
	private GameLetter[] ownLetters;
	private int currentPlayer;
	private boolean gameHasStarted;
	private int playerPosition;

	public GameState(GameLetter[][] matrix, Player[] players,
			GameLetter[] ownLetters, int currentPlayer, boolean gameHasStarted, int playerPosition) {
		this.players = players;
		this.ownLetters = ownLetters;
		this.currentPlayer = currentPlayer;
		this.gameHasStarted = gameHasStarted;
		for (GameLetter[] glrow : matrix) {
			for (GameLetter gl : glrow) {
				letters.add(gl);
			}
		}
		this.playerPosition = playerPosition;

	}

	public List<GameLetter> getLetters() {
		return letters;
	}

	public GameLetter[][] getLetterMatrix() {
		GameLetter[][] matrix = new GameLetter[17][17];
		for (int i = 0; i < matrix.length; i++) {
			for (int j = 0; j < matrix[i].length; j++) {
				matrix[j][i] = letters.get(matrix.length * j + i);
			}
		}
		return matrix;
	}

	public Player[] getPlayers() {
		return players;
	}

	public GameLetter[] getOwnLetters() {
		return ownLetters;
	}

	public int getCurrentPlayer() {
		return currentPlayer;
	}

	public boolean hasGameStarted() {
		return gameHasStarted;
	}

	public int getPlayerPosition() {
		return playerPosition;
	}
}